<?php
/*
 * Hooligan - A sports facilities management software
 * Copyright (C) 2009/2010 Gianluca Bargelli <g.bargelli@gmail.com>,
 * Andrea Biocco <abiocco@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Project home: <http://code.google.com/hooligan>
 *
*/
require_once('../Controller/Common/Controller_Common_Config.php');
require_once('../Template/Template_Admin.php');
/**
 * Description of Controller_AmministratoreImpianti
 *
 * @author Andrea Biocco
 */

class Controller_Impianti_AdminImpianto {

    public static function rimImpianto($id_impianto) {
        $sql = "delete from Impianto where id_impianto='".$id_impianto."'";
        $connection=new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
        $db = new Model_Db($connection);
        $db->eseguiQuery($sql);
        header('location:adminImpianto.php');
    }
    
    public static function listImpianti() {
        if (!array_key_exists('id_impianto',$_GET)) {
            echo("<table>");
            Tools_CustomDebug::niceDump($_GET);
            $connection=new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
            $db = new Model_Db($connection);
            $sql="SELECT * FROM `Impianto`";
            $rs=$db->eseguiQuery($sql);
            echo("<tr>");
            echo("<th>");
                echo ("Codice identificativo");
            echo("</th>");
            echo("<th>");
                echo ("Tipo");
            echo("</th>");
            echo("<th>");
                echo ("Giocatori per squadra");
            echo("</th>");
          //  echo("<th>");
          //      echo ("Descrizione");
          //  echo("</th>");
            echo("<th>");
                echo ("Tariffa (€/ora)");
            echo("</th>");
            echo("<th>");
                echo ("Lunghezza (m)");
            echo("</th>");
            echo("<th>");
                echo ("Larghezza (m)");
            echo("</th>");
            echo("<th>");
                echo ("Tipologia superficie");
            echo("</th>");
            echo("<th>");
                echo ("Al coperto?");
            echo("</th>");
            echo("<th>");
                echo ("Via");
            echo("</th>");
            echo("<th>");
                echo ("N° civico");
            echo("</th>");
            echo("<th>");
                echo ("Città");
            echo("</th>");
            echo("<th>");
                echo ("Ultima Modifica");
            echo("</th>");
            echo("<th colspan='2'>");
            echo ("Operazioni possibili");
            echo("</th>");
                echo("</tr>");
            while($row = $rs->fetch_array(MYSQLI_ASSOC)) {
                echo("<tr>");
                echo("<td>");
                echo $row['id_impianto'];
                echo("</td>");
                echo("<td>");
                echo $row['tipo_impianto'];
                echo("</td>");
                echo("<td>");
                echo $row['num_giocatori_calcio'];
                echo("</td>");
                //echo("<td>");
               // echo $row['descrizione'];
               // echo("</td>");
                 echo("<td>");
                echo $row['tariffa'];
                echo("</td>");
                echo("<td>");
                echo $row['lunghezza'];
                echo("</td>");
                echo("<td>");
                echo $row['larghezza'];
                echo("</td>");
                echo("<td>");
                echo $row['superficie'];
                echo("</td>");
                echo("<td>");
                 if ($row['interno']==="0")
                    echo("No");
                else echo("Si");
                echo("</td>");
                echo("<td>");
                echo $row['via'];
                echo("</td>");
                echo("<td>");
                echo $row['numero_civico'];
                echo("</td>");
                echo("<td>");
                echo $row['citta'];
                echo("</td>");
                echo("<td>");
                echo $row['Amministratore_Utente_username'];
                echo("</td>");
                echo("<td>");
                ?>
<!-- il parametro get azione=modifica nn serve-->
<a href="../http/modificaImpianto.php?id_impianto=<?php echo $row['id_impianto']; ?>&azione=modifica">Modifica</a>
                <?php
                echo("</td>");
                echo("<td>");
                ?>
<a href="adminImpianto.php?id_impianto=<?php echo $row['id_impianto']; ?>&azione=rimuovi">Rimuovi</a>
                <?php
                echo("</td>");
                echo("</tr>");
            }
            echo("</table>");
            echo("<a href='../http/addImpianto.php'>Aggiungi un impianto</a>");
        } else if($_GET['azione']==='rimuovi') {
            Controller_Impianti_AdminImpianto::rimImpianto($_GET['id_impianto']);
        } 
    }
}
?>
